package com.example.madplayer;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LocalMusicAdapter extends BaseAdapter {
	
	private List<String> music_list;
	private Context context;
	
	public LocalMusicAdapter(Context context, List<String> list) {
		music_list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return music_list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return music_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.common_list_item2, null);

			// Creates a ViewHolder and store references to the two children
			// views
			// we want to bind data to.
			holder = new ViewHolder();
			holder.text = (TextView) convertView.findViewById(R.id.common_text);
			convertView.setTag(holder);
		} else {
			// Get the ViewHolder back to get fast access to the TextView
			// and the ImageView.
			holder = (ViewHolder) convertView.getTag();
		}

		holder.text.setText(music_list.get(position));

		// Bind the data efficiently with the holder.
		return convertView;
	}
	
	static class ViewHolder {
		private TextView text;
	}
	
}
